import cv2 as cv
import numpy as np
img = cv.imread('../../data/jwithWhiteNoiseLeft.png',0)
kernel =np.ones((5,5),np.uint8)
# equal to input-open
blackhat = cv.morphologyEx(img,cv.MORPH_TOPHAT,kernel)
# input-open
closing =cv.morphologyEx(img,cv.MORPH_OPEN,kernel)
cmi =closing-img
# merge all imgs on horizontal direction
res =np.hstack((img,closing,blackhat,cmi))

cv.imshow('res', res)
cv.waitKey(0)
cv.destroyAllWindows()